package com.project2.shiro;

import org.apache.shiro.web.session.mgt.DefaultWebSessionManager;
import org.springframework.stereotype.Component;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import java.io.Serializable;

/**
 * TODO
 *
 * @param
 * @author wj
 * @return
 */
@Component
public class SessionManager extends DefaultWebSessionManager {
    private static final String MARKET_ADMIN_TOKEN="X-CskaoyanMarket-Admin-Token";
    private static final String MARKET_WX_TOKEN="X-CskaoyanMarket-Token";

    @Override
    protected Serializable getSessionId(ServletRequest request, ServletResponse response) {
        HttpServletRequest req = (HttpServletRequest) request;
        String header = req.getHeader(MARKET_ADMIN_TOKEN);
        if (header!=null&&!"".equals(header)){
            return header;
        }
        String header1 = req.getHeader(MARKET_WX_TOKEN);
        if (header1!=null&&!"".equals(header1)){
            return header1;
        }

        return super.getSessionId(request,response);
    }
}
